package com.sjgtw.cloud.web.cuttingSlopeProtection.controller;

import com.sjgtw.cloud.common.core.utils.poi.ExcelUtil;
import com.sjgtw.cloud.common.core.web.controller.BaseController;
import com.sjgtw.cloud.common.core.web.domain.AjaxResult;
import com.sjgtw.cloud.common.core.web.page.TableDataInfo;
import com.sjgtw.cloud.web.cuttingSlopeProtection.domain.CuttingSlopeProtection;
import com.sjgtw.cloud.web.cuttingSlopeProtection.service.ICuttingSlopeProtectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 路堑护坡Controller
 * 
 * @author lvyoufang
 * @date 2024-03-14
 */
@RestController
@RequestMapping("/cuttingSlopeProtection")
@Api(tags = "2.3、应急设施-路堑护坡")
public class CuttingSlopeProtectionController extends BaseController
{
    @Autowired
    private ICuttingSlopeProtectionService cuttingSlopeProtectionService;

    /**
     * 查询路堑护坡列表
     */
    @ApiOperation(value = "查询路堑护坡列表")
    @GetMapping("/list")
    public TableDataInfo list(CuttingSlopeProtection cuttingSlopeProtection)
    {
        startPage();
        List<CuttingSlopeProtection> list = cuttingSlopeProtectionService.selectCuttingSlopeProtectionList(cuttingSlopeProtection);
        return getDataTable(list);
    }

    /**
     * 导出路堑护坡列表
     */
    @ApiOperation(value = "导出路堑护坡列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, CuttingSlopeProtection cuttingSlopeProtection)
    {
        List<CuttingSlopeProtection> list = cuttingSlopeProtectionService.selectCuttingSlopeProtectionList(cuttingSlopeProtection);
        ExcelUtil<CuttingSlopeProtection> util = new ExcelUtil<CuttingSlopeProtection>(CuttingSlopeProtection.class);
	    try {
		    util.exportExcel(response, list, "路堑护坡数据");
	    } catch (IOException e) {
		    e.printStackTrace();
	    }
    }

    /**
     * 获取路堑护坡详细信息
     */
    @ApiOperation(value = "获取路堑护坡详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cuttingSlopeProtectionService.selectCuttingSlopeProtectionById(id));
    }

    /**
     * 新增路堑护坡
     */
    @ApiOperation(value = "新增路堑护坡")
    @PostMapping
    public AjaxResult add(@RequestBody CuttingSlopeProtection cuttingSlopeProtection)
    {
        return toAjax(cuttingSlopeProtectionService.insertCuttingSlopeProtection(cuttingSlopeProtection));
    }

    /**
     * 修改路堑护坡
     */
    @ApiOperation(value = "修改路堑护坡")
    @PutMapping
    public AjaxResult edit(@RequestBody CuttingSlopeProtection cuttingSlopeProtection)
    {
        return toAjax(cuttingSlopeProtectionService.updateCuttingSlopeProtection(cuttingSlopeProtection));
    }

    /**
     * 删除路堑护坡
     */
    @ApiOperation(value = "删除路堑护坡")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(cuttingSlopeProtectionService.deleteCuttingSlopeProtectionByIds(ids));
    }


    /**
     * 删除路堑护坡
     */
    @ApiOperation(value = "删除路堑护坡")
    @GetMapping("/delete/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(cuttingSlopeProtectionService.deleteCuttingSlopeProtectionById(id));
    }
}
